<%@ page import="com.ws.haungjia.utils.Res" %>
<!DOCTYPE html>
<html lang="zh-CN">
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旅游产品下单</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        .product-info {
            display: flex;
            margin-bottom: 30px;
            border-bottom: 1px solid #eee;
            padding-bottom: 20px;
        }
        .product-image {
            width: 40%;
            margin-right: 20px;
        }
        .product-image img {
            width: 100%;
            border-radius: 8px;
        }
        .product-details {
            width: 60%;
        }
        .price {
            font-size: 24px;
            color: #e74c3c;
            font-weight: bold;
            margin: 10px 0;
        }
        .original-price {
            text-decoration: line-through;
            color: #95a5a6;
            font-size: 16px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #34495e;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        .quantity-control {
            display: flex;
            align-items: center;
        }
        .quantity-btn {
            background-color: #3498db;
            color: white;
            border: none;
            width: 40px;
            height: 40px;
            font-size: 20px;
            cursor: pointer;
            border-radius: 4px;
        }
        .quantity-input {
            width: 60px;
            text-align: center;
            margin: 0 10px;
        }
        .total-price {
            font-size: 20px;
            font-weight: bold;
            color: #e74c3c;
            text-align: right;
            margin: 20px 0;
        }
        .status {
            padding: 10px;
            background-color: #f39c12;
            color: white;
            text-align: center;
            border-radius: 4px;
            font-weight: bold;
            margin-bottom: 20px;
        }
        .btn-submit {
            background-color: #2ecc71;
            color: white;
            border: none;
            padding: 12px 20px;
            font-size: 18px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            transition: background-color 0.3s;
        }
        .btn-submit:hover {
            background-color: #27ae60;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>旅游产品下单</h1>

    <div class="status">待支付</div>

    <div class="product-info">
        <div class="product-image">
            <img src="<%=Res.fileUri%>${lunshan.zhutu}" alt="旅游景点">
        </div>
        <div class="product-details">
            <h2>${lunshan.zhuangtai}</h2>
            <div class="price">
                ¥<span id="unit-price">${lunshan.jiage}</span>
            </div>
            <p>出发地: ${lunshan.chufadi}</p>
            <p>行程天数: ${lunshan.tianshu}</p>
        </div>
    </div>

    <div class="form-group">
        <label for="order-date">出发日期</label>
        <input type="date" id="order-date" required>
    </div>

    <div class="form-group">
        <label for="travelers">出行人数</label>
        <div class="quantity-control">
            <button class="quantity-btn" id="decrease">-</button>
            <input type="number" class="quantity-input" id="travelers" value="1" min="1">
            <button class="quantity-btn" id="increase">+</button>
        </div>
    </div>

    <div class="form-group">
        <label for="contact-name">联系人姓名</label>
        <input type="text" id="contact-name" required>
    </div>

    <div class="form-group">
        <label for="contact-phone">联系人电话</label>
        <input type="tel" id="contact-phone" required>
    </div>

    <div class="total-price">
        总价: ¥<span id="total-price" name="jiage">150</span>
    </div>

    <button class="btn-submit" id="submit-order">提交订单</button>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const unitPrice = ${lunshan.jiage};
        const travelersInput = document.getElementById('travelers');
        const decreaseBtn = document.getElementById('decrease');
        const increaseBtn = document.getElementById('increase');
        const totalPriceElement = document.getElementById('total-price');

        // 设置默认日期为明天
        const tomorrow = new Date();
        tomorrow.setDate(tomorrow.getDate() + 1);
        document.getElementById('order-date').valueAsDate = tomorrow;

        // 更新总价
        // 更新总价（无单人附加费）
        function updateTotalPrice() {
            const travelers = parseInt(travelersInput.value);
            const totalPrice = unitPrice * travelers;
            totalPriceElement.textContent = totalPrice;
        }

        // 减少人数
        decreaseBtn.addEventListener('click', function() {
            let value = parseInt(travelersInput.value);
            if (value > 1) {
                travelersInput.value = value - 1;
                updateTotalPrice();
            }
        });

        // 增加人数
        increaseBtn.addEventListener('click', function() {
            let value = parseInt(travelersInput.value);
            travelersInput.value = value + 1;
            updateTotalPrice();
        });

        // 直接输入人数
        travelersInput.addEventListener('change', function() {
            if (this.value < 1) this.value = 1;
            updateTotalPrice();
        });

        // 提交订单
        document.getElementById('submit-order').addEventListener('click', function() {
            const orderDate = document.getElementById('order-date').value;
            const travelers = travelersInput.value;
            const contactName = document.getElementById('contact-name').value;
            const contactPhone = document.getElementById('contact-phone').value;

            if (!orderDate || !contactName || !contactPhone) {
                alert('请填写完整信息');
                return;
            }

            // 这里应该是实际的订单提交逻辑
            alert(`订单提交成功!\n出发日期: ${orderDate}\n出行人数: ${travelers}\n总价: ¥${totalPriceElement.textContent}`);

            // 模拟订单状态变化
            document.querySelector('.status').textContent = '已支付';
            document.querySelector('.status').style.backgroundColor = '#2ecc71';
        });

        // 初始化总价
        updateTotalPrice();
    });
</script>
</body>
</html>